R for Spatial Statistics

 

Working with Vector Data in sf

sf is a new package and apepars to be the leading contender to replace rgdal and sp. sf reads and writes shapefiles and also has a large number of vector transforms available (see resources at the bottom of the page).

Reading and Displaying Data

The code below will read a shapefile into a data table.

# Load library
library('sf')
library("tibble") # required for read (at least).  This installs about 10 other libraries

FilePath="D:/GISData/2_Working/WGS84_UTM_Zone_10_North/County_Humboldt/Cities/cities2sp.shp"

# Loads data table
TheCities <- read_sf(FilePath)

plot(TheCities)

Because we now have a data frame, all of the other functions such as nrow() and ncol() work with the data.

Additional Resources

Simple Features for R - website for SF with great quick reference.